<?php

class shoutbox_widget extends iKernel{
	function shoutbox_widget(){
		$tpl = new Template;
		//include("locale/".$current_language.".php");
		
		include("locale/en.php");


		$this->content ="<table width='100%'>";
		
		$db = new DB("shoutbox");
		$db->setColPrefix("shout_");
		$db->select();	
		$db->sort ="shout_id DESC";
		$db->limit = "5";
		$bg_color = "c2c2c2";
		while($db->nextRecord()){
			if($bg_color == "c2c2c2"){
				$bg_color = "292929";
			}else{
				$bg_color == "c2c2c2";
			}
			$this->content .= "
			<tr><td>
			<a href='".iUrl::makeClean("/?lang=".$current_language."&amp;page=profile&amp;argv1=".$this->getuser("id", $db->poster)."")."'>".$this->getuser("firstname", $db->poster)." ".$this->getuser("lastname", $db->poster)."</a><br />
			".parsesmileys($db->message)."
			</td>
			</tr>";
		}
		$this->content .="</table>";
		
		if(isset($_POST['post_shout']) && isset($_POST['shout_message'])){
			if(empty($_POST['shout_message'])){
				$this->content .= "<br /><label style='color: red; font-weight: bold;'>Shout message was empty.</label>";
			}else{
				if(iUSER){
				$db = new DB("shoutbox");
				$db->setColPrefix("shout_");
				$db->poster = USER_ID;
				$db->posted = time();
				$db->message = $_POST['shout_message'];
				$db->insert();
				$this->redirect(" ");
				}
			}
		}
		
		if(iUSER){
		$this->content .= "
		<form method='post'>
			<textarea name='shout_message'></textarea>
			<input type='submit' value='Shout' name='post_shout'>
		</form>
			";
		}else{
			$this->content .= "<br /><strong>".$locale['shoutbox_restriction']."</strong>";
		}
	
	
		$tpl->title = "Shoutbox";
		$tpl->content = $this->content;
		$tpl->sidebar = "left";
		$tpl->Build("view/modules");
	}

}


?>